﻿//SmartSettings.xaml.cs
//Copyright (c) 2013 StockSharp LLC, all rights reserved.
//This code module is part of StockSharp library.
//This code is licensed under the GNU GENERAL PUBLIC LICENSE Version 3.
//See the file License.txt for the license details.
//More info on: http://stocksharp.com

namespace StockSharp.Smart.Xaml
{
	using System.Net;

	using Ecng.Common;

	using StockSharp.BusinessEntities;
	using StockSharp.Smart;
	using StockSharp.Xaml;

	/// <summary>
	/// Визуальная панель настроек <see cref="SmartTrader"/>.
	/// </summary>
	public partial class SmartSettings : ITraderSettingsPanel
	{
		/// <summary>
		/// Создать <see cref="SmartSettings"/>.
		/// </summary>
		public SmartSettings()
		{
			InitializeComponent();
		}

		/// <summary>
		/// <see cref="SmartTrader.Login"/>.
		/// </summary>
		public string Login
		{
			get { return LoginCtrl.Text; }
			set { LoginCtrl.Text = value; }
		}

		/// <summary>
		/// <see cref="SmartTrader.Password"/>.
		/// </summary>
		public string Password
		{
			get { return PasswordCtrl.Password; }
			set { PasswordCtrl.Password = value; }
		}

		/// <summary>
		/// <see cref="SmartTrader.Address"/>.
		/// </summary>
		public EndPoint Address
		{
			get { return AddressCtrl.SelectedAddress; }
			set { AddressCtrl.SelectedAddress = value; }
		}

		bool ITraderSettingsPanel.IsValid
		{
			get { return !Login.IsEmpty() && !Password.IsEmpty() && Address != null; }
		}

		void ITraderSettingsPanel.Save(ITrader trader)
		{
			var smartTrader = (SmartTrader)trader;

			smartTrader.Login = Login;
			smartTrader.Password = Password;
			smartTrader.Address = Address;
		}

		void ITraderSettingsPanel.Load(ITrader trader)
		{
			var smartTrader = (SmartTrader)trader;

			Login = smartTrader.Login;
			Password = smartTrader.Password;
			Address = smartTrader.Address;
		}
	}
}